//
// Created by 25313 on 2025/8/7.
//
class Solution {
public:
    int sum(TreeNode* root, int parent, int grandparent)
    {
        if(root == nullptr)
            return 0;
        int res = 0;
        if(grandparent%2 == 0)
            res += root->val;
        res += sum(root->left, root->val, parent);
        res += sum(root->right, root->val, parent);
        return res;
    }
    int sumEvenGrandparent(TreeNode* root)
    {
        return sum(root, -1, -1);
    }

};